package com.zengde.ai_sandbox.test.testthread.mathteacher;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class MathTeacher  {
    private int count = 1000;
    public synchronized void add() {
        count++;
        println(1);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized void sub() {
        count--;
        println(2);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    private void println(int type){
        if (type == 1) {
            System.out.println("当前操作线程为:"+Thread.currentThread().getName()+" 加值，"+":当前值：" + count);
        } else {
            System.out.println("当前操作线程为:"+Thread.currentThread().getName()+" 减值,"+":当前值：" + count);
        }
    }

}
